/**
 * Company : Thai Informatic System Co., Ltd.
 * Created By : Dr.Tree
 * Created On : May 9, 2012  12:36:32 PM 
 * e-Mail : chatree@tis.co.th
 * Mobile Phone : (+66) 087-921-5115
 * Package Name : apps.business.process.sales.bank.deduction.requested
 * File Name : MktBankDeduRequProcessing.java
 * TODO
 */
package apps.business.process.sales.bank.deduction.requested;

import java.util.List;
import org.apache.log4j.Logger;

import promis.utility.CommonService;
import sap.business.sd.outbound.VwSyncMktBankDeduRequService;
import jpa.entitys.synchro.staging.SdCustoRequDeducOutb;
import apps.business.process.SyncProcessorCommons;
import apps.promis.out.sales.VwSyncMktBankDeduRequAction;

/**
 * @author chatree
 *
 */
public class MktBankDeduRequProcessing extends SyncProcessorCommons {
	
	private static final Logger log = Logger.getLogger(MktBankDeduRequProcessing.class);	
	
	
	/**
	 * 		String company = "SP";
			String project = "SPLVILLE-PRAGSA";
			String contractNo = "CS-1206-000019-0";
			String status = "A";
			String syncIsstaging = "N";
	 * @param company
	 * @param project
	 * @param contractNo
	 * @param status
	 * @param syncIsstaging
	 * @throws Exception
	 */
	public void Processing(String company, String project, String contractNo, String status, String syncIsstaging) throws Exception {
		try
		{	
			//Save Data to Staging
			UPD_PROMISUseTime(true, false, null);
			List<SdCustoRequDeducOutb> SdCustoRequDeducOutb_lst = new VwSyncMktBankDeduRequAction().CreateToStaging(company, project, contractNo, status, syncIsstaging);
			UPD_PROMISUseTime(false, true, null);
			System.out.println("Create sales deduction request [" + company + "||" + project + "||" + contractNo + "||" + status + "||" + syncIsstaging + "] to staging size="+ CommonService.getSize(SdCustoRequDeducOutb_lst) +"---> ");
			
			//Sending to SAP
			if(CommonService.getSize(SdCustoRequDeducOutb_lst) > 0){
				UPD_SENDUseTime(true, false, SdCustoRequDeducOutb_lst.get(0).getInstanceNo());
				new VwSyncMktBankDeduRequService().SendingToSAP(SdCustoRequDeducOutb_lst);
				UPD_SENDUseTime(false, true, SdCustoRequDeducOutb_lst.get(0).getInstanceNo());
			}			
			System.out.println("Sending Sales Deduction Request to SAP size="+ CommonService.getSize(SdCustoRequDeducOutb_lst) +"---> ");
			
		}catch(Exception e)
		{
			log.error(e.getMessage());
			System.err.println(e.getMessage());
		}
	}

	@Deprecated
	private void start() throws Exception {
		
		try
		{
			VwSyncMktBankDeduRequAction obj = new VwSyncMktBankDeduRequAction();
			
			String company = "SP";
			String project = "SPLVILLE-PRAGSA";
			String contractNo = "CS-1206-000019-0";
			String status = "A";
			String syncIsstaging = "N";
			
			//Save Data to Staging
			log.info("Start Create Sales Deduction Request to Staging --------------------------------------> ");
			List<SdCustoRequDeducOutb> SdCustoRequDeducOutb_lst = obj.CreateToStaging(company, project, contractNo, status, syncIsstaging);
			log.info("End Create Sales Deduction Request to Staging --------------------------------------> ");
			
			//Sending to SAP
			log.info("Start Sending Sales Deduction Request to SAP --------------------------------------> ");
			new VwSyncMktBankDeduRequService().SendingToSAP(SdCustoRequDeducOutb_lst);
			log.info("End Sending Sales Deduction Request to SAP --------------------------------------> ");
			
		}catch(Exception e)
		{
			log.error(e.getMessage());
			System.err.println(e.getMessage());
		}
	}

//	/**
//	 * @param args
//	 */
//	public static void main(String[] args) {
//		// TODO Auto-generated method stub		
//		try{
//			
//			MktBankDeduRequProcessing obj = new MktBankDeduRequProcessing();
//			
//			obj.start();
//			
//		}catch(Exception e){
//			
//			log.error(e);
//			e.printStackTrace();
//		}
//	}

}
